var targetSelId;
var targetSelectedValue;
var startIndex;

function ajaxFn(url,callback){
	var xhr;
	if (window.ActiveXObject) { // 是否IE
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xhr = new XMLHttpRequest();
	}
	xhr.onreadystatechange = function () {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) { // http协议号
				var result = xhr.responseText;
				callback(result);
			}
		}
	};
	xhr.open("post", url); // 建立连接
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send(null);

}

function getJsonByAjax(yid,did,selvalue,start,ctx){
	targetSelId=did;
    targetSelectedValue=selvalue;
    startIndex = start;
	var url=ctx+'/guestroom/FloorManageAction!getFloorByBuildId.ef';
	var id = document.getElementById(yid).value;
	if(id ==''){
		$(did).length=0;
		return;
	}
    ajaxFn(url+'?buildingId='+id,createSel);
}
  
   //根据部门ID查相关的营收科目
   function getJsonByAjax1(yid,did,selvalue,start,ctx){
	targetSelId=did;
    targetSelectedValue=selvalue;
    startIndex = start;
	var url=ctx+'/reception/RevenurItemsManageAction!getRevenurItemsManageByorgid.ef';
	var id = document.getElementById(yid).value;
	if(id ==''){
		$(did).length=0;
		return;
	}
    ajaxFn(url+'?orgId='+id,createSel);
}


function createSel(value){
	var optionsInfo = eval("("+ value +")");																	
	var targetSelNode = document.getElementById(targetSelId);	
	
	targetSelNode.length = startIndex;
	for( var o in  optionsInfo){
		if(!-[1,]){//IE
			targetSelNode.add( createOption( o,optionsInfo[o] ) );
		}else{//FF
			targetSelNode.add( createOption( o,optionsInfo[o] ),null );
		}
	}
	
	if(targetSelectedValue){
		targetSelNode.value=targetSelectedValue;
	}
	
}

 function createOption( value,text ){    
    	var opt = document.createElement("option");
    	opt.value = value;
    	opt.text = text;
    	return opt;
    }